# Open a connection to the log file
log_file <- file("replication_log.txt", open = "wt")

# Start logging both output and errors
sink(log_file)
sink(log_file, type = "message")

#Descriptive stats
print("Table 1: Descriptive statistics:")
ds.df #from 'Replication1'

# Print model summary
print("Table 2: Model 1, 1975-2021:")
summary(sac.resc)

print("Table 2: Model 2, 1991-2021:")
summary(sac.resc1991)

print("Table 2: Model 3, 1999-2021:")
summary(sac.resc1999)

list1 = c(indirect1975, indirect1991, indirect1999)

print("Short-run spatial effects in Table 2:")
list1

print("Table 3: Model 1, 1975-2021:")
summary(sacL.resc)

print("Table 3: Model 2, 1991-2021:")
summary(sacL.resc1991)

print("Table 3: Model 3, 1999-2021:")
summary(sacL.resc1999)

list2 = c(indirect_SR_1975, indirect_SR_1991, indirect_SR_1999)

print("Short-run spatial effects in Table 3:")
list2

list3 = c(lrss1975, lrss1991, lrss1999)

print("LRSS spatial effects in Table 3:")
list3

print("Table 4: Model 1, 1975-2021:")
summary(sacL.resc.no.us)

print("Table 4: Model 2, 1993-2021:")
summary(sacL.resc1993.ru)

print("Table 4: Model 3, 1993-2021:")
summary(sacL.resc1993.distru)

print("Table 4: Model 4, 1993-2021:")
summary(sacL.dist.usneigh)

print("Table 4: Model 5, 1995-2002:")
summary(sacL.rep1995)


# Stop logging
sink(type = "message")
sink()

# Close the connection to the log file
close(log_file)


#Saving figures
#Figure 1
ggsave("figure1.png", fig1)

#Figure 2 
ggsave("figure2.png", fig2)

